home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 738 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.8 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solon.com (Peter Seebach)
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: printf() format extensions - looking for beta testers...
  5. Date: 13 Apr 1996 09:40:26 -0500
  6. Organization: Usenet Fact Police (Undercover)
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4koecq$8up@solutions.solon.com>
  10. References: <4kgljv$l2p@solutions.solon.com> <4klicn$ndl@solutions.solon.com> <4kll9l$o5h@solutions.solon.com> <4kobun$8i2@solutions.solon.com>
  11. Reply-To: seebs@solon.com
  12. NNTP-Posting-Host: solutions.solon.com
  13.  
  14. In article <4kobun$8i2@solutions.solon.com>,
  15. Sean 'Captain Napalm' Conner <spc@gate.net> wrote:
  16. >  But there is a potential problem with doing this.  What if you use a
  17. >pre-compiled module that has extended printf(), say, using '%#' (unbeknownst
  18. >to you, the documentation may be a bit lax (happens enough)).  What happens
  19. >when you try to extend printf() using '%#'?  With possible different
  20. >semantics (different type, say)?
  21.  
  22. That's why mine is not like the plan 9 fmtinstall().  In my current design,
  23. assuming that we have
  24.     typedef int (*fmtconv)();
  25. (args will vary as I struggle with the design), you install a format with
  26.     fmtconv format(int c, fmtconv);
  27.  
  28. which installs a new format and returns the previous one.  There are special
  29. magic fmtconvs called FMT_IGN (to make a character no longer a format
  30. character), FMT_DFL (to reset to the default), and FMT_GET, which doesn't
  31. install anything, but returns the current conversion func.
  32.  
  33. This has been described as overengineering, but is there for precisely
  34. that reason.
  35.  
  36. %# would be a poor choice; the conversion func for %# is one which returns
  37. a magic cookie to set the alternate format flag.  :)
  38.  
  39. But yeah, I've been thinking about it.
  40.  
  41. >  -spc (Or does your printf() report a redefinition error?)
  42.  
  43. Nope.
  44.  
  45. I'm also considering the sfio magic of
  46.     %(foo)
  47. calling a conversion func attached to the string "foo".  This seems
  48. frivolous for small apps, but if you look at a POSIX system, with
  49. N+1 magic types like uid_t and gid_t, it might be useful.
  50.  
  51. I've been starting to get dazzled by the vast array of cool ideas
  52. various previous implementations have come up with.  sfio has a base
  53. flag, which could make the lives of thousands of first year students much
  54. easier.
  55.  
  56. The problem is mostly coming up with a consistent way of parsing
  57. things such that no currently standardized call to printf will change
  58. behavior unless you've done something else (like call format()) which
  59. is not standardized.
  60.  
  61. (Well, that would be trivial; but doing that and providing useful extensions
  62. is more difficult.)
  63.  
  64. -s
  65. -- 
  66. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  67. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  68. FUCK the communications decency act.  Goddamned government.  [literally.]
  69. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  70.